home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / Technical Documentation / Develop / Additional Articles / Developing Symbiotic Apps / Symbiotic Samples / Symbiotic client source / Trident.cw10_pp / CTridentWindow.cp < prev    next >
Encoding:
Text File  |  1996-10-15  |  6.3 KB  |  245 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CTridentView.cp                        ©1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5.  
  6. #include "CTridentWindow.h"
  7. #include "CTridentApp.h"
  8. #include "CTridentCmds.h"
  9. #include "CTridentIdler.h"
  10. #include "TridentAESuite.h"
  11. #include <LStream.h>
  12.  
  13. #ifndef __TOOLUTILS__
  14. #include <ToolUtils.h>
  15. #endif
  16. //==============================window stuff====================================
  17.  
  18. CTridentWindow*
  19. CTridentWindow::CreateTridentWindowStream(
  20.     LStream    *inStream)
  21. {
  22.     return (new CTridentWindow(inStream));
  23. }
  24.  
  25. CTridentWindow::~CTridentWindow()
  26. {
  27.  
  28.  if (mSuperCommander != NULL)
  29.      {
  30.      if (this->IsConnected())
  31.         this->SendQuit();
  32. //     ((CTridentApp*)mSuperCommander)->CloseWindow(this->mPaneID);
  33.      fAEAddressDesc.dataHandle = NULL;    //eventually want to send a AEQuit!
  34.     }
  35. }
  36. CTridentWindow::CTridentWindow(
  37.     LStream    *inStream)
  38.             : LWindow(inStream)
  39. {
  40.     fAEAddressDesc.descriptorType = typeNull;
  41.     fAEAddressDesc.dataHandle = NULL;
  42. }
  43. void CTridentWindow::SetPortRefNum(short thePortRefNum) 
  44. {
  45.     fPortRefNum = thePortRefNum;
  46. }
  47.  
  48. void CTridentWindow::Connect() 
  49. {
  50.     MyBrowser((CTridentWindow*) this);
  51.     if (this->IsConnected())
  52.         this->SendNull();
  53.     if (this->IsConnected())
  54.         this->SendVersion();
  55.  
  56.     if (myView != NULL)
  57.          if (myView->fHeartBeatMonitor != NULL)
  58.             myView->fHeartBeatMonitor->StartIdling();
  59.     
  60. }
  61.  
  62. void CTridentWindow::SendNull() 
  63. {
  64.     long clientSessionID = (long) this->fPortRefNum;
  65.     AEAddressDesc& theAddress = this->fAEAddressDesc;
  66.     AppleEvent    appleEvent, replyEvent;
  67.     OSErr err = AECreateAppleEvent(kAEAUXSuite, kAENull, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &appleEvent);
  68.     err = AECreateDesc(typeNull, NULL, 0, &replyEvent);
  69.     err = AEPutParamPtr(&appleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));            
  70.     UAppleEventsMgr::SendAppleEventWithReply(appleEvent,replyEvent, TRUE);
  71.     AEDisposeDesc(&replyEvent);
  72.     AEDisposeDesc(&appleEvent);
  73. }
  74.  
  75. void CTridentWindow::SendQuit() 
  76. {
  77.     long clientSessionID = (long) this->fPortRefNum;
  78.     AEAddressDesc& theAddress = this->fAEAddressDesc;
  79.     AppleEvent    appleEvent , replyEvent;
  80.     
  81. //    if (::Alert(1000, 0) != 2)
  82. //        {
  83.     OSErr err = ::AECreateAppleEvent(kAEAUXSuite, kAEQuit, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &appleEvent);
  84.     err = AEPutParamPtr(&appleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));            
  85.     err = ::AECreateDesc(typeNull, NULL, 0, &replyEvent);
  86.  
  87.     err = ::AESend(&appleEvent, &replyEvent, kAENoReply | kAEDontReconnect, kAENormalPriority, kAEDefaultTimeout, nil, nil);
  88. //        }
  89.     AEDisposeDesc(&appleEvent);
  90.     AEDisposeDesc(&replyEvent);
  91. }
  92.  
  93. void CTridentWindow::SendVersion() 
  94. {
  95.     OSErr err;    
  96.     AppleEvent    versionappleEvent, reply2Event;
  97.     DescType actualCode;
  98.     long actualSize;
  99.     long clientSessionID = (long) this->fPortRefNum;
  100.     AEAddressDesc& theAddress = this->fAEAddressDesc;
  101.         OSType myVersion = '6.66';    //the version from hell
  102.     Handle    initialVersionH = ::Get1Resource('rDrD', 128);
  103. //    if (::Alert(1001, 0) != 2)
  104. //        {
  105.     if (initialVersionH != nil)
  106.         ::BlockMove(*initialVersionH, &myVersion, 4);
  107. //        }
  108.     err = AECreateAppleEvent(kAEAUXSuite, kAEVersion, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &versionappleEvent);
  109.     err = ::AEPutParamPtr(&versionappleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));            
  110.     err = ::AECreateDesc(typeNull, NULL, 0, &reply2Event);
  111.     err = ::AEPutParamPtr(&versionappleEvent, keyAEVersion, typeChar, &myVersion, sizeof(OSType));            
  112.  
  113.     err = ::AESend(&versionappleEvent, &reply2Event, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
  114.  
  115.     LStr255    theText;
  116.  
  117.     char status[1];
  118.     if (&reply2Event != nil) {
  119.         err = ::AEGetParamPtr(&reply2Event, keyErrorNumber, typeChar, &actualCode,  (Ptr)status, sizeof(char), &actualSize);
  120.         if (*status == 'S')
  121.             {
  122.             CTridentView* myListBox = (CTridentView*) this->FindPaneByID('winb');
  123.  
  124.             theText = "It is alive";
  125.             if (myListBox != NULL)
  126.                 myListBox->SetDescriptor(theText);
  127.             myView = myListBox;
  128.             }
  129.         AEDisposeDesc(&reply2Event);
  130.     }
  131.     AEDisposeDesc(&versionappleEvent);
  132.  
  133. }
  134. Boolean
  135. CTridentWindow::ObeyCommand(
  136.     CommandT    inCommand,
  137.     void        *ioParam)
  138. {
  139.     Boolean        cmdHandled = true;
  140.     
  141.     switch (inCommand) {
  142.         
  143.         case 421:
  144.             this->SendInterval(10);
  145.             break;
  146.         case 422:
  147.             this->SendInterval(30);
  148.             break;
  149.         case 423:
  150.             this->SendInterval(60);
  151.             break;
  152.         case 424:
  153.             this->SendInterval(600);
  154.             break;
  155.         case 425:
  156.             this->SendInterval(3600);
  157.             break;
  158.             
  159.         default:
  160.             cmdHandled = inherited::ObeyCommand(inCommand, ioParam);
  161.             break;
  162.     }
  163.         
  164.     return cmdHandled;
  165. }
  166.  
  167. void CTridentWindow::SendInterval(long seconds) 
  168. {
  169.     if (myView != NULL)
  170.         myView->SendInterval(seconds);
  171. }
  172.  
  173. void CTridentWindow::SendHeart() 
  174. {
  175.     if (this->IsConnected())
  176.         {
  177.         long clientSessionID = (long) this->fPortRefNum;
  178.         AEAddressDesc& theAddress = this->fAEAddressDesc;
  179.  
  180.         AppleEvent    heartappleEvent;
  181.         OSErr err = AECreateAppleEvent(kAEAUXSuite, kAEHeartBeat, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &heartappleEvent);
  182.         err = ::AEPutParamPtr(&heartappleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));            
  183.         UAppleEventsMgr::SendAppleEvent(heartappleEvent, TRUE);
  184.         if (myView != NULL)
  185.             myView->ResetTicks();
  186.         }
  187. }
  188.  
  189. Boolean CTridentWindow::IsConnected() 
  190. {
  191.     return (fAEAddressDesc.dataHandle != NULL);
  192. }
  193.  
  194.  
  195. void CTridentWindow::SetAddress(TargetID& theTarget) 
  196. {
  197.     // Accepts result of PPCBrowser call. May fail.
  198.  
  199.     AEAddressDesc    targetAddress;
  200.  
  201.     ThrowIfOSErr_(AECreateDesc(typeTargetID, Ptr(&theTarget), sizeof(theTarget),
  202.                            &targetAddress));
  203.     fAEAddressDesc = targetAddress;
  204. }
  205.  
  206. void
  207. CTridentWindow::HandleAppleEvent(
  208.     const AppleEvent    &inAppleEvent,
  209.     AppleEvent            &outAEReply,
  210.     AEDesc                &outResult,
  211.     long                inAENumber)
  212. {
  213.     if (myView != NULL)
  214.         {
  215.         myView->ResetTicks();
  216.         myView->HandleAppleEvent(inAppleEvent, outAEReply,
  217.                                 outResult, inAENumber);
  218.         }
  219. }
  220. void
  221. CTridentWindow::FindCommandStatus(
  222.     CommandT    inCommand,
  223.     Boolean        &outEnabled,
  224.     Boolean        &outUsesMark,
  225.     Char16        &outMark,
  226.     Str255        outName)
  227. {
  228.  
  229.     switch (inCommand) {
  230.         case 421:
  231.         case 422:
  232.         case 423:
  233.         case 424:
  234.         case 425:
  235.             if (myView != NULL)
  236.                 myView->FindCommandStatus(inCommand, outEnabled,
  237.                                     outUsesMark, outMark, outName);
  238.             break;
  239.         default:
  240.             inherited::FindCommandStatus(inCommand, outEnabled,
  241.                                 outUsesMark, outMark, outName);
  242.     }
  243. }
  244.  
  245.